import 'package:flutter/material.dart';
import 'package:ichinesereader/models/report/bookchartdata.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:get/get.dart';

class BookLevelWidget extends StatelessWidget {
  BookLevelWidget({Key? key, required this.bookchartdata}) : super(key: key);
  final List<BookChartData> bookchartdata;

  @override
  Widget build(BuildContext context) {
    Log.debug('build BookLevelWidget');
    TooltipBehavior _tooltipbehavior = TooltipBehavior(enable: true);

    return SfCartesianChart(
        title: ChartTitle(
          alignment: ChartAlignment.near,
          text: 'Number of Books by Levels'.tr,
          textStyle: TextStyle(
              fontFamily: 'Montserrat',
              color: Get.isDarkMode
                  ? Get.theme.primaryColorDark
                  : Get.theme.primaryColorLight),
        ),
        legend: Legend(
          isVisible: false,
          textStyle: TextStyle(
              fontFamily: 'Montserrat',
              color: Get.isDarkMode
                  ? Get.theme.primaryColorDark
                  : Get.theme.primaryColorLight),
        ),
        tooltipBehavior: _tooltipbehavior,
        primaryXAxis: CategoryAxis(),
        series: <CartesianSeries>[
          ColumnSeries<BookChartData, String>(
              name: 'Number of Books'.tr,
              dataSource: bookchartdata,
              xValueMapper: (BookChartData data, _) =>
                  data.item.replaceAll('Level 0', 'N/A'),
              yValueMapper: (BookChartData data, _) => data.account,
              pointColorMapper: (BookChartData data, _) => data.color),
        ]);
  }
}
